IF EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'spReportsFoldersReadyForMerging_RetrieveAll')
	BEGIN
		PRINT 'Dropping Procedure spReportsFoldersReadyForMerging_RetrieveAll'
		DROP  Procedure  spReportsFoldersReadyForMerging_RetrieveAll
	END

GO

PRINT 'Creating Procedure spReportsFoldersReadyForMerging_RetrieveAll'
GO

CREATE Procedure spReportsFoldersReadyForMerging_RetrieveAll
	(
		@tuser char(8) = null, 
		@FILENO char(20) = null, 
		@d_id varchar(50) = null, 
		@d_folder varchar(50) = null, 
		@d_loc varchar(50) = null, 
		@ILPNO char(20) = null, 
		@a_code char(8) = null, 
		@a_desc char(30) = null, 
		@a_from char(10) = null, 
		@a_to char(10) = null, 
		@d_status varchar(50) = null, 
		@d_match numeric = null, 
		@d_exist numeric = null, 
		@FSTATUS char(10) = null, 
		@LOCNO char(10) = null, 
		@d_accno varchar(50) = null, 
		@d_doctype varchar(50) = null, 
		@d_lasttran DateTime = null
	)
AS
    /* 
    ------------------------------------------------------------------------------
    - Change History
    - --------------
    - Date          Description
    ------------------------------------------------------------------------------
    - 10/15/2007	Initial version created
    ------------------------------------------------------------------------------
    */
	
	SET NOCOUNT ON
	
	-- Retrieve the relevant records
	SELECT  *
	FROM	ReportsFoldersReadyForMerging
	
	WHERE	(@tuser IS NULL OR ReportsFoldersReadyForMerging.tuser = @tuser)
	  AND	(@FILENO IS NULL OR ReportsFoldersReadyForMerging.FILENO = @FILENO)
	  AND	(@d_id IS NULL OR ReportsFoldersReadyForMerging.d_id LIKE @d_id + '%')
	  AND	(@d_folder IS NULL OR ReportsFoldersReadyForMerging.d_folder LIKE @d_folder + '%')
	  AND	(@d_loc IS NULL OR ReportsFoldersReadyForMerging.d_loc LIKE @d_loc + '%')
	  AND	(@ILPNO IS NULL OR ReportsFoldersReadyForMerging.ILPNO = @ILPNO)
	  AND	(@a_code IS NULL OR ReportsFoldersReadyForMerging.a_code = @a_code)
	  AND	(@a_desc IS NULL OR ReportsFoldersReadyForMerging.a_desc = @a_desc)
	  AND	(@a_from IS NULL OR ReportsFoldersReadyForMerging.a_from = @a_from)
	  AND	(@a_to IS NULL OR ReportsFoldersReadyForMerging.a_to = @a_to)
	  AND	(@d_status IS NULL OR ReportsFoldersReadyForMerging.d_status LIKE @d_status + '%')
	  AND	(@d_match IS NULL OR ReportsFoldersReadyForMerging.d_match = @d_match)
	  AND	(@d_exist IS NULL OR ReportsFoldersReadyForMerging.d_exist = @d_exist)
	  AND	(@FSTATUS IS NULL OR ReportsFoldersReadyForMerging.FSTATUS = @FSTATUS)
	  AND	(@LOCNO IS NULL OR ReportsFoldersReadyForMerging.LOCNO = @LOCNO)
	  AND	(@d_accno IS NULL OR ReportsFoldersReadyForMerging.d_accno LIKE @d_accno + '%')
	  AND	(@d_doctype IS NULL OR ReportsFoldersReadyForMerging.d_doctype LIKE @d_doctype + '%')
	  AND	(@d_lasttran IS NULL OR ReportsFoldersReadyForMerging.d_lasttran = @d_lasttran)

	-- Return to calling method
	RETURN
GO
